<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>商家列表 - 在线论坛</title>
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../elementui/elementui.css">
<!--  <link rel="stylesheet" href="../../css/font-awesome.min.css">-->
  <style>
  /* 全局样式 */
  body {
    font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
    background-color: #f7f8fa;
    margin: 0;
    padding: 0;
    color: #333;
  }

  .section {
    width: 1200px;
    max-width: 100%;
    margin: 0 auto;
  }

  .breadcrumb-preview {
    padding: 15px 7%;
    margin: 0 auto;
    border-color: #ebeef5;
    background: #fff;
    border-width: 0 0 1px;
    width: 100%;
    border-style: solid;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
  }
  
  .breadcrumb-preview .el-button {
    transition: all 0.3s ease;
  }

  .breadcrumb-preview .el-button:hover {
    transform: translateX(-3px);
  }
  
  .list-preview {
    padding: 0;
    margin: 0 auto;
    flex-wrap: wrap;
    background: transparent;
    display: flex;
    width: 100%;
    position: relative;
  }
  
  /* 搜索表单样式 */
  .list-form-pv {
    padding: 20px 7%;
    margin: 20px 0 0;
    border-color: #ebeef5;
    align-items: center;
    flex-wrap: wrap;
    background: #fff;
    border-width: 0;
    display: flex;
    width: 100%;
    border-style: solid;
    height: auto;
    order: 1;
    border-radius: 8px;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05);
  }
  
  .list-form-pv .el-form-item {
    margin: 0 15px 0 0;
  }
  
  .list-form-pv .lable {
    width: auto;
    padding: 0 10px;
    line-height: 40px;
    display: inline-block;
    font-weight: 500;
    color: #606266;
  }
  
  .list-form-pv .el-input {
    border-radius: 4px;
    padding: 0;
    margin: 0;
    outline: none;
    color: #333;
    width: 280px;
    font-size: 14px;
    line-height: 40px;
    height: 40px;
    transition: all 0.3s ease;
  }
  
  .list-form-pv .search-btn {
    cursor: pointer;
    border: 0;
    padding: 0 20px;
    margin: 0 0 0 10px;
    outline: none;
    color: #fff;
    border-radius: 4px;
    background: #F5BB00;
    width: auto;
    font-size: 14px;
    line-height: 40px;
    height: 40px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(245, 187, 0, 0.3);
  }
  
  .list-form-pv .search-btn:hover {
    background: #e5af00;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 187, 0, 0.4);
  }
  
  .list-form-pv .add-btn {
    cursor: pointer;
    border: 0;
    padding: 0 20px;
    margin: 0 10px 0 0;
    outline: none;
    color: #fff;
    border-radius: 4px;
    background: #333;
    width: auto;
    font-size: 14px;
    line-height: 40px;
    height: 40px;
    transition: all 0.3s ease;
  }
  
  /* 筛选选项样式 */
  .select2 {
    width: 100%;
    padding: 15px 7%;
    margin: 20px 0 0;
    background: #fff;
    height: auto;
    order: 2;
    border-radius: 8px;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05);
  }
  
  .select2 .list {
    padding: 8px 0;
    margin: 0;
    border-color: #ebeef5;
    background: none;
    border-width: 0 0 1px;
    width: 100%;
    position: relative;
    border-style: dashed;
    height: auto;
  }
  
  .select2 .list:last-child {
    border-bottom: none;
  }
  
  .select2 .label {
    padding: 0 10px 0 0;
    color: #606266;
    font-weight: 500;
    display: inline-block;
    width: auto;
    line-height: 36px;
    font-size: 14px;
  }
  
  .select2 .item-body {
    width: auto;
    display: inline-block;
    height: auto;
  }
  
  .select2 .item {
    padding: 0 15px;
    margin: 0 8px 8px 0;
    color: #606266;
    cursor: pointer;
    text-align: center;
    outline: none;
    background: #f5f7fa;
    display: inline-block;
    width: auto;
    border: none;
    line-height: 36px;
    font-size: 13px;
    height: 36px;
    border-radius: 18px;
    transition: all 0.3s ease;
  }
  
  .select2 .item:hover {
    background: #ebeef5;
    color: #F5BB00;
  }
  
  .select2 .item.active {
    padding: 0 15px;
    margin: 0 8px 8px 0;
    color: #fff;
    cursor: pointer;
    text-align: center;
    outline: none;
    background: #F5BB00;
    display: inline-block;
    width: auto;
    border: none;
    line-height: 36px;
    font-size: 13px;
    height: 36px;
    border-radius: 18px;
    box-shadow: 0 2px 8px rgba(245, 187, 0, 0.3);
  }
  
  /* 商家列表样式 */
  .list3 {
    padding: 0;
    overflow: hidden;
    flex-wrap: wrap;
    background: transparent;
    display: flex;
    width: 100%;
    clear: both;
    justify-content: flex-start;
    height: auto;
    gap: 20px;
  }
  
  .list3 .list-item {
    cursor: pointer;
    padding: 0;
    margin: 0 0 20px;
    overflow: hidden;
    background: #fff;
    display: flex;
    width: calc(25% - 15px);
    flex-direction: column;
    border-radius: 10px;
    position: relative;
    border: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,0.05);
  }
  
  .list3 .list-item:hover {
    transform: translateY(-6px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  }
  
  .list3 .img-box {
    border: none;
    width: 100%;
    padding: 0;
    overflow: hidden;
    height: 220px;
    border-radius: 10px 10px 0 0;
  }
  
  .list3 .img-box img {
    width: 100%;
    object-fit: cover;
    display: block;
    height: 100%;
    transition: transform 0.8s ease;
  }
  
  .list3 .list-item:hover .img-box img {
    transform: scale(1.05);
  }
  
  .list3 .item-info {
    padding: 15px;
    overflow: hidden;
    flex: 1;
    display: flex;
    height: auto;
    flex-direction: column;
  }
  
  .list3 .item-info .title {
    color: #303133;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.3s ease;
  }
  
  .list3 .list-item:hover .item-info .title {
    color: #F5BB00;
  }
  
  .list3 .item-info .price {
    color: #F5BB00;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
  }
  
  .list3 .item-info .time {
    padding: 8px 0;
    margin-bottom: 5px;
    border-color: #ebeef5;
    border-style: solid;
    border-width: 0 0 1px 0;
    color: #909399;
    font-size: 13px;
  }
  
  .list3 .item-info .collect {
    padding: 8px 0;
    color: #909399;
    font-size: 13px;
    display: flex;
    align-items: center;
  }
  
  .list3 .item-info .icon {
    margin-right: 5px;
  }
  
  /* 分页样式 */
  .pagination {
    padding: 20px 7%;
    margin: 20px auto 40px;
    white-space: nowrap;
    overflow: hidden;
    color: #333;
    text-align: center;
    width: 100%;
    clear: both;
    font-weight: 500;
    order: 50;
  }
  
  /* 预览图样式 */
  .preview-dialog .el-dialog {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  }
  
  .preview-dialog .el-dialog__header {
    padding: 15px 20px;
    background: #f7f8fa;
    border-bottom: 1px solid #ebeef5;
  }
  
  .preview-dialog .el-dialog__body {
    padding: 0;
  }
  
  /* 响应式设计 */
  @media screen and (max-width: 1200px) {
    .list3 .list-item {
      width: calc(33.33% - 14px);
    }
  }
  
  @media screen and (max-width: 992px) {
    .list-form-pv {
      padding: 15px 5%;
    }
    
    .select2 {
      padding: 12px 5%;
    }
    
    .list3 .list-item {
      width: calc(50% - 10px);
    }
    
    .list-form-pv .el-input {
      width: 220px;
    }
  }
  
  @media screen and (max-width: 768px) {
    .list-form-pv {
      flex-direction: column;
      align-items: flex-start;
    }
    
    .list-form-pv .el-form-item {
      width: 100%;
      margin: 0 0 10px 0;
    }
    
    .list-form-pv .search-btn {
      margin-top: 10px;
    }
    
    .list3 .list-item {
      width: 100%;
    }
  }
  </style>
</head>
<body>
  <div id="app">
    <div class="main-container">
      <!-- 返回按钮 -->
      <div v-if="centerType" class="breadcrumb-preview">
        <el-button size="mini" type="text" @click="backClick">
          <i class="el-icon-arrow-left"></i> 返回
        </el-button>
      </div>
      
      <!-- 列表主体 -->
      <div class="list-preview">
        <!-- 搜索表单 -->
        <div class="list-form-pv">
          <div class="el-form-item">
            <div class="lable">商家名称：</div>
            <el-input v-model="formSearch.shangjiamingcheng" placeholder="请输入商家名称" @keydown.enter.native="getList(1)" clearable prefix-icon="el-icon-search"></el-input>
          </div>
          <div class="el-form-item">
            <div class="lable">商家地址：</div>
            <el-input v-model="formSearch.shangjiadizhi" placeholder="请输入商家地址" @keydown.enter.native="getList(1)" clearable prefix-icon="el-icon-location"></el-input>
          </div>
          <el-button class="search-btn" type="primary" @click="getList(1)">
            <i class="el-icon-search" style="margin-right: 5px;"></i>查询
          </el-button>
        </div>
        
        <!-- 筛选选项 -->
        <div class="select2" v-if="selectOptionsList && selectOptionsList.length > 0">
          <div class="list" v-for="(item,index) in selectOptionsList" :key="index">
            <div class="label">{{item.name}}：</div>
            <div class="item-body">
              <div class="item" @click="selectClick(item,-1)" :class="item.check == -1 ? 'active' : ''">全部</div>
              <div class="item" @click="selectClick(item,i)" :class="item.check == i ? 'active' : ''" v-for="(opt,i) in item.list" :key="i">{{opt}}</div>
            </div>
          </div>
        </div>
        
        <!-- 商家列表 -->
        <div class="list" style="width: 100%; padding: 0 7%; margin: 20px auto; background: transparent; order: 4;">
          <div class="list3">
            <div v-for="(item, index) in dataList" :key="index" @click="toDetail(item)" class="list-item">
              <div class="img-box">
                <img v-if="item.shangjiatupian && item.shangjiatupian.substr(0,4)=='http'" :src="item.shangjiatupian.split(',')[0]" class="image" />
                <img v-else :src="baseUrl + (item.shangjiatupian?item.shangjiatupian.split(',')[0]:'')" class="image" />
              </div>
              <div class="item-info">
                <div style="width: 100%; padding: 0; flex: 1;">
                  <div class="title">{{item.shangjiaxingming}}</div>
                  <div v-if="item.price" class="price"><span style="font-size: 12px;">￥</span>{{item.money}}</div>
                  <div class="time">
                    <span class="icon fa fa-clock-o"></span>
                    <span class="text">{{item.addtime}}</span>
                  </div>
                  <div class="collect">
                    <span class="icon fa fa-star-o"></span>
                    <span class="text">收藏: {{item.sfsh || 0}}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          
          <!-- 无数据提示 -->
<!--          <el-empty v-if="!dataList || dataList.length === 0" description="暂无数据"></el-empty>-->
        </div>
        
        <!-- 分页 -->
        <el-pagination
          background
          id="pagination"
          class="pagination"
          :page-size="pageSize"
          :page-sizes="pageSizes"
          prev-text="<"
          next-text=">"
          :hide-on-single-page="false"
          layout="total,prev,pager,next,sizes,jumper"
          :total="total"
          @current-change="curChange"
          @size-change="sizeChange"
          @prev-click="prevClick"
          @next-click="nextClick"
        ></el-pagination>
      </div>
      
      <!-- 预览图弹窗 -->
      <el-dialog title="预览图" :visible.sync="previewVisible" width="50%" class="preview-dialog">
        <img :src="previewImg" alt="" style="width: 100%;">
      </el-dialog>
    </div>
  </div>
  
  <!-- 引入JS库 -->
  <script src="../../js/vue.js"></script>
  <script src="../../js/config.js"></script>
  <script src="../../elementui/elementui.js"></script>
  <script src="../forum/axios.js"></script>
<!--  <script src="../../js/jquerys.min.js"></script>-->
  
  <script>
    var app = new Vue({
      el: '#app',
      data: {
        selectIndex: 0,
        selectOptionsList: [],
        baseUrl: '',
        formSearch: {
          shangjiamingcheng: '',
          shangjiadizhi: '',
        },
        dataList: [],
        total: 1,
        pageSize: 8,
        pageSizes: [10, 20, 30, 50],
        totalPage: 1,
        curFenlei: '全部',
        centerType: false,
        previewImg: '',
        previewVisible: false,
        sortType: 'id',
        sortOrder: 'desc',
        isAuth: function(tableName, option) {
          if (option == '新增' || option == '修改' || option == '删除' || option == '更新') {
            return true
          }
          return true
        }
      },
      created() {
        const url = new URL(window.location.href);
        if(url.searchParams.get('centerType')){
          this.centerType = true;
        }
        this.baseUrl = 'http://localhost:8080/springboot1a8gh/';
        this.getList(1);
      },
      methods: {
        selectClick(row, index) {
          row.check = index;
          if(index == -1){
            this.formSearch[row.tableName] = '';
          } else {
            this.formSearch[row.tableName] = row.list[index];
          }
          this.getList();
        },
        add() {
          let path = './add.html';
          if(this.centerType){
            path = path + '?centerType=1';
          }
          window.location.href = path;
        },
        getList(page = 1) {
          const params = {page, limit: this.pageSize};
          let searchWhere = {};
          if (this.formSearch.shangjiamingcheng != '') searchWhere.shangjiamingcheng = '%' + this.formSearch.shangjiamingcheng + '%';
          if (this.formSearch.shangjiadizhi != '') searchWhere.shangjiadizhi = '%' + this.formSearch.shangjiadizhi + '%';
          if (this.sortType) searchWhere.sort = this.sortType;
          if (this.sortOrder) searchWhere.order = this.sortOrder;
          
          let url = `${this.baseUrl}shangjia/${this.centerType ? 'page' : 'list'}`;
          axios.get(url, {params: Object.assign(params, searchWhere)}).then(res => {
            if (res.data.code == 0) {
              this.dataList = res.data.data.list;
              this.total = Number(res.data.data.total);
              this.pageSize = Number(res.data.data.pageSize);
              this.totalPage = res.data.data.totalPage;
              this.pageSizes = [this.pageSize, this.pageSize*2, this.pageSize*3, this.pageSize*5];
            }
          });
        },
        curChange(page) {
          this.getList(page);
        },
        prevClick(page) {
          this.getList(page);
        },
        sizeChange(size){
          this.pageSize = size;
          this.getList(1);
        },
        nextClick(page) {
          this.getList(page);
        },
        imgPreView(url){
          this.previewImg = url;
          this.previewVisible = true;
        },
        toDetail(item) {
          let params = `?id=${item.id}`;
          if(this.centerType){
            params += `&centerType=1`;
          }
          window.location.href = `./detail.html${params}`;
        },
        backClick() {
          history.back();
        }
      }
    });
  </script>
</body>
</html>